package com.Darkra1Zzz.service.impl;


import com.Darkra1Zzz.dao.AdminDao;
import com.Darkra1Zzz.entity.Admin;
import com.Darkra1Zzz.service.AdminService;
import com.Darkra1Zzz.util.MD5;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author DarkraiZzz
 * @Time 2021/6/14 22:34
 * @Version 1.0
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminDao adminDao;

    @Override
    public Admin login(String email, String pwd) {
        Admin admin = adminDao.login(email);
        System.out.println("------");
        System.out.println(admin.getPwd());
        System.out.println("----------输入的："+MD5.encrypByMd5(pwd));
        if ((MD5.encrypByMd5(MD5.encrypByMd5(pwd)).equals(admin.getPwd()))){
            return admin;
        }else {
            return null;
        }
    }

    @Override
    public boolean addAdmin(Admin admin) {
        if (adminDao.login(admin.getEmail())!=null){
            return false;
        }else {
            admin.setPwd(MD5.encrypByMd5(MD5.encrypByMd5(admin.getPwd())));
            return adminDao.addAdmin(admin);
        }
    }
}
